﻿using System;
namespace Producers.Liiklusregister.Xtee.Riik.Ee.Producer.Liiklusregister {
    
    
    [global::Xtee.Core.Attributes.XmlTypeAttribute(Name="soidukiteAndmedResponse", Namespace="http://producers.liiklusregister.xtee.riik.ee/producer/liiklusregister", Target=typeof(SoidukiteAndmedResponse))]
    public class SoidukiteAndmedResponseSerializer : global::Xtee.Core.Types.AbstractXteeSerializable {
        
        protected ISoidukiteAndmedResponse clazz;
        
        public SoidukiteAndmedResponseSerializer(ISoidukiteAndmedResponse clazz) {
            this.clazz = clazz;
        }
        
        public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXml(Writer);
            if (((clazz.Soiduk == null) 
                        || (clazz.Soiduk.Count < 1m))) {
                throw new global::Xtee.Core.Exceptions.MinOccurrenceException(1m, "soiduk");
            }
            for (int x = 0; ((clazz.Soiduk != null) 
                        && (x < clazz.Soiduk.Count)); x = (x + 1)) {
                Writer.WriteStartElement("soiduk");
                if (clazz.Soiduk[x]!=null) {
                    global::Xtee.Core.SerializationMetadata metaSoiduk = this.GetMetaData(clazz.Soiduk[x]);
                    Writer.WriteTypeAttribute(metaSoiduk.TypeQualifiedName.Namespace, metaSoiduk.TypeQualifiedName.Name);
                    metaSoiduk.NewSerializer(clazz.Soiduk[x]).WriteXml(Writer);
                }
                else {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Soiduk");
                }
                Writer.WriteEndElement();
            }
        }
        
        public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXml(Reader);
            clazz.Soiduk = new System.Collections.Generic.List<global::Producers.Liiklusregister.Xtee.Riik.Ee.Producer.Liiklusregister.ISoidukiAndmed>();
            for (; ((Reader.NodeType != System.Xml.XmlNodeType.EndElement) 
                        && (Reader.LocalName == "soiduk")); ) {
                if (Reader.LocalName=="soiduk") {
                    if (Reader.IsElementNil()) {
                        throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>soidukiteAndmedResponse>soiduk");
                    }
                    global::Xtee.Core.SerializationMetadata metaSoiduk = this.GetMetaData<global::Producers.Liiklusregister.Xtee.Riik.Ee.Producer.Liiklusregister.ISoidukiAndmed>(Reader, "soidukiAndmed", "http://producers.liiklusregister.xtee.riik.ee/producer/liiklusregister");
                    global::Producers.Liiklusregister.Xtee.Riik.Ee.Producer.Liiklusregister.ISoidukiAndmed item = metaSoiduk.NewEntity<global::Producers.Liiklusregister.Xtee.Riik.Ee.Producer.Liiklusregister.ISoidukiAndmed>();
                    clazz.Soiduk.Add(item);
                    if ((Reader.IsEmptyElement == false)) {
                        Reader.ReadStartElement("soiduk");
                        metaSoiduk.NewSerializer(item).ReadXml(Reader);
                        Reader.ReadEndElement();
                    }
                    else {
                        Reader.Skip();
                    }
                }
                else {
                    throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>soidukiteAndmedResponse>soiduk", Reader.LocalName);
                }
            }
            if ((clazz.Soiduk.Count < 1m)) {
                throw new global::Xtee.Core.Exceptions.MinOccurrenceException(1m, "soiduk");
            }
        }
    }
}
